package com.atrix.CinemaView.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.atrix.CinemaView.dao.FileDao;
import com.atrix.CinemaView.pojo.dto.info.PhotoContainerInfo;
import com.atrix.CinemaView.pojo.dto.PhotoStreamData;
import com.atrix.CinemaView.pojo.Container;
import com.atrix.CinemaView.pojo.FileObj;
import com.atrix.CinemaView.service.PhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PhotoServiceImpl implements PhotoService {
    @Autowired
    FileDao fileDao;
    
    @Override
    public PhotoStreamData getRandomPhoto() {
        List<Container<FileObj>> containerList = fileDao.getPhotoContainerList();
        Container<FileObj> container = containerList.get(RandomUtil.randomInt(containerList.size()));
        return new PhotoStreamData(container.getData().get(RandomUtil.randomInt(container.getSize())));
    }
    
    @Override
    public PhotoStreamData getRandomInContainer(int index) {
        Container<FileObj> container = fileDao.getPhotoContainer(index);
        return new PhotoStreamData(container.getData().get(RandomUtil.randomInt(container.getSize())));
    }
    
    @Override
    public PhotoStreamData getPhoto(int containerIndex, int index) {
        return new PhotoStreamData(fileDao.getPhoto(containerIndex, index));
    }
    
    @Override
    public List<PhotoContainerInfo> getAllContainerInfo() {
        return fileDao.getPhotoInfoList();
    }
    
    @Override
    public int getContainerCount() {
        return fileDao.getPhotoInfoList().size();
    }
}
